package com.yiwan.app.preventionsis.util;

import android.os.Environment;

import java.io.File;

public class StorageUtil {
    private static boolean mExternalStorageAvailable = false;
    private static boolean mExternalStorageWriteable = false;
    private static File appExtFilePath;
    private static File appExtCachePath;
    private static File appFilePath;
    private static File appCachePath;

    public static boolean isExtStorageReadable() {
        updateExtStorageState();
        //Log.d("isExtStorageReadable", "mExternalStorageAvailable: " + mExternalStorageAvailable);
        return mExternalStorageAvailable;
    }

    public static boolean isExtStorageWriteable() {
        updateExtStorageState();
      //Log.d.d("isExtStorageWriteable", "mExternalStorageAvailable: " + mExternalStorageAvailable);
        return mExternalStorageWriteable;
    }

    public static void updateExtStorageState() {
        String state = Environment.getExternalStorageState();
    //Log.dog.d("updateExtStorageState", "state: " + state);
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            mExternalStorageAvailable = mExternalStorageWriteable = true;
        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false;
        } else {
            mExternalStorageAvailable = mExternalStorageWriteable = false;
        }

    }

    public static File getAppFilePath() {
        if (appFilePath == null) {
            appFilePath = PreventionSis.getInstance().getFilesDir();
        }
  //Log.d Log.d("getAppFilePath", appFilePath + "");
        return appFilePath;
    }

    public static File getAppCachePath() {
        if (appCachePath == null) {
            appCachePath = PreventionSis.getInstance().getCacheDir();
        }
//Log.d   Log.d("getAppCachePath", appCachePath + "");
        return appCachePath;
    }

    public static File getAppExtFilePath() {
        if (appExtFilePath == null) {
            appExtFilePath = PreventionSis.getInstance().getExternalFilesDir(null);
        }
        //Log.d     Log.d("getAppExtFilePath", appExtFilePath + "");
        return appExtFilePath;
    }

    public static File getAppExtCachePath() {
        if (appExtCachePath == null) {
            appExtCachePath = PreventionSis.getInstance().getExternalCacheDir();
        }
      //Log.d       Log.d("getAppExtCachePath", appExtCachePath + "");
        return appExtCachePath;
    }
}
